package com.itheima.sc.service.order;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.api.order.OmsOrderApi;
import com.itheima.sc.pojo.order.OmsOrderOperateHistory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@Service
public class OmsOrderUtil {
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @DubboReference
    private OmsOrderApi omsOrderApi;

    public void saveHistoryOpe(ArrayList<Long> ids, Integer status, String note) {
        //保存操作历史
//        String userId = stringRedisTemplate.opsForValue().get("CHECK_ADMINID");
        // 根据用户获得操作人员昵称
        try {
            for (Long id : ids) {
                OmsOrderOperateHistory omsOrderOperateHistory = new OmsOrderOperateHistory();
                omsOrderOperateHistory.setOrderId(Convert.toLong(id));
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:dd");
                omsOrderOperateHistory.setCreateTime(
                        simpleDateFormat.parse(simpleDateFormat.format(
                                new Date(System.currentTimeMillis())
                        ))
                );
                omsOrderOperateHistory.setOrderStatus(status);
                omsOrderOperateHistory.setNote(note);
                omsOrderOperateHistory.setOperateMan("操作人的用户id是"+"后台管理人员");
                //保存数据
                omsOrderApi.addOperateHistory(omsOrderOperateHistory);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
